package com.example.littleken.ormlite_text.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**引导页Adapter
 * Created by littleken on 2018/6/20.
 */
public class PageAdapter extends PagerAdapter {
    //布局源
    private List<View> guideViews;
    //初始化布局源
    public PageAdapter(List<View> guideViews) {
        this.guideViews = guideViews;
    }

    @Override
    public int getCount() {
        return guideViews==null?0:guideViews.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    //插入布局
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View child = guideViews.get(position);
        container.addView(child);
        return child;
    }

    //销毁布局
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
       container.removeView(guideViews.get(position));
    }
}
